"""
This file demonstrates writing tests using the unittest module. These will pass
when you run "manage.py test". 

If you want to run tests in a specific class, run "manage.py test agbay.[class_name]".
If you want to run a specific test in a specific class, run "manage.py test agbay[class_name].[specific_test]".

Replace this with more appropriate tests for your application.
"""

from agbay.models import AgbayUsers, Items, Ratings, Notifications
from datetime import datetime
import views
from django.utils import unittest
from django.test.client import Client


class SimpleTest(unittest.TestCase):
    def test_basic_addition(self):
        """
        Tests that 1 + 1 always equals 2.
        """
        self.assertEqual(1 + 1, 2)

class Workflows(unittest.TestCase):
	def setUp(self):
		self.client = Client()
	
	def workflow1(self):
		"""
		Outline: User accesses the login page
				 User attempts to login
		"""
		suite = unittest.TestSuite()
		suite.addTest(LoginTestCase('test_login_url'))
		suite.addTest(LoginTestCase('test_login'))
		unittest.TextTestRunner(verbosity=2).run(suite)
	
	
class LoginTestCase(unittest.TestCase):
	def setUp(self):
		self.client = Client()

	def test_login_url(self):
		"""
		Purpose: Tests the login link 
		"""
		print '\nTesting login link'
		request = self.client.get('/login/')
		self.assertEqual(request.status_code, 200)
		print '\nLogin link is successful'
	
	def test_login(self):
		"""
		Purpose: Tests login
		"""
		print '\nTesting login'
		print '\nAttempting to login as User: Test, Password: Test'
		request = self.client.get('/login/')
		request = views.attempt_login(request, "Test", "Test")
		self.assertEqual(request.status_code, 200)
		print '\nLogin attempt is successful'
		

class RegistrationTest(unittest.TestCase):
	def setUp(self):
		self.client = Client()
		
	def test_registration_url(self):
		"""
		Purpose: Tests the "Register" link
		"""
		print "\nTesting registration link"
		request = self.client.get('/register/')
		self.assertEqual(request.status_code, 200)
		print '\nRegistration link is successful. Whoop!'
		
	def test_valid_registration(self):
		"""
		Purpose: Tests registration with correct inputs
		"""
		print '\nAttempting to register with valid inputs...'
		response = self.client.post('/register/', {'nameParam': 'john', 'emailParam': 'smith@smith.smith',  'pass1Param': '1234',  'pass2Param': '1234'})
		print self.assertEqual(response.status_code, 200)
		print '\nRegistration has worked woooo!'
		
	def test_invalid_registration(self):
		"""
		Purpose: Tests registration with incorrect inputs
		(should fail)
		"""
		print '\nAttempting to register with invalid inputs (mismatching passwords)...'
		response = self.client.post('/register/', {'nameParam': 'john', 'emailParam': 'smith@smith.smith',  'pass1Param': '1234',  'pass2Param': '4321'})
		print self.assertEqual(response.status_code, 200)

class CreateItemTestCase(unittest.TestCase):
	def setUp(self):
		self.client = Client()
	
	def test_create_item_url(self):
		print "\nTesting Create Item link"
		request = self.client.get('/create_item/')
		self.assertEqual(request.status_code, 200)
		print '\Create Item link is successful.'
	
	def test_valid_item_creation(self):
		print '\nAttempting to create item with valid inputs...'
		response = self.client.post('/create_item/', {'SellerUserId': 'john', 'BuyerUserId': 'smith',  'MinBid': '1.24',  'MaxBid': '2.00', 'CurBid': '0', 'BuyPrice': '20.00', 'IsCompleted': 'False', 'CreatedAt': datetime.now(), 'UpdatedAt': datetime.now(), 'EndingAt': datetime.now() })
		print "\nTesting Create Item via HTML request..."
		self.assertEqual(response.status_code, 200)
		#print "\nChecking Changes in Item test database..."
		#self.assertEqual(AgbayUsers.objects.all().count(), 1)
	
	


